<!DOCTYPE html>
<html lang="en">

	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
		<meta name="description" content="">
		<meta name="author" content="">
		<!-- STYLESHEETS -->
		<!--[if lt IE 9]><script src="../../js/flot/excanvas.min.js"></script><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
		<link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
		<link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
		<link rel="stylesheet" type="text/css" href="../../css/responsive.css">

		<link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
		<!-- file-input -->
		<link rel="stylesheet" type="text/css" href="../../js/file-input/fileinput.css" />
		<!-- SELECT2 -->
		<link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css" />
		<!-- UNIFORM -->
		<link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css" />
		<!-- datatable -->
		<link rel="stylesheet" href="../../js/datatables/datatable.css">
		<!-- WIZARD -->
		<link rel="stylesheet" type="text/css" href="../../js/bootstrap-wizard/wizard.css" />
		  <link rel="stylesheet" href="../../js/datepicker/datepicker.css">
		<!-- FONTS
	<link href='http://fonts.useso.com/css?family=Open+Sans:300,400,600,700' rel='stylesheet' type='text/css'>
-->
		<!-- JQUERY -->
		<script src="../../js/jquery/jquery-2.0.3.min.js"></script>
		<script src="../../js/common.js"></script>
	</head>

	<body>
		<header class="navbar clearfix" id="header">
		</header>

		<!-- PAGE -->
		<section id="page">
			<!-- SIDEBAR -->
			<div id="sidebar" class="sidebar">
				<div class="sidebar-menu nav-collapse">

					<!-- SIDEBAR MENU -->
					<ul>

					</ul>
					<!-- /SIDEBAR MENU -->
				</div>

			</div>
			<!-- /SIDEBAR -->
			<div id="main-content">

				<div class="container">
					<div class="row">
						<div id="content" class="col-lg-12">
							<!-- PAGE HEADER-->
							<div class="row">
								<div class="col-sm-12">
									<div class="page-header">
										<!-- STYLER -->

										<!-- /STYLER -->
										<!-- BREADCRUMBS -->
										<ul class="breadcrumb">
											<li>
												<i class="fa fa-home"></i>
												<a href="index.html">首页</a>
											</li>
											<li>
												<a href="#">商品管理</a>
											</li>
											<li>维护商品</li>
										</ul>
										<!-- /BREADCRUMBS -->

									</div>
								</div>
							</div>
							<!-- /PAGE HEADER -->
							<!-- SAMPLE -->
							<form id="form_coupon">
							<div class="row col-md-12">
							<input name="id" type="hidden">
								<div class="col-md-3" style="width: 25%;height:200px">
									<div class="" style="text-align: center;margin-top:30%;font-size:24px;">基本信息</div>
								</div>
								<div class="col-md-9">
									<div class="box border primary" style="height:400px">
										<div class="form-group mrg-bt10-right" style="margin-top:10px;">
											<label class="control-label col-md-3">供应商名称：</label>
											<div class="col-md-8 inline supplierName">
												
											</div>
										</div>
										<div class="form-group mrg-bt10-right" style="margin-top:10px;">
											<label class="control-label col-md-3">合同编号：</label>
											<div class="col-md-8 inline contractCode">
												
											</div>
										</div>
										<div class="form-group mrg-bt10-right" style="margin-top:10px;">
											<label class="control-label col-md-3">合同金额：</label>
											<div class="col-md-8 inline contractPrice" >
												
											</div>
										</div>
										<div class="form-group mrg-bt10-right">
											<label class="control-label col-md-3">结算类型：</label>
											<div class="col-md-8 inline settlementMode">
												
											</div>
										</div>
										<div class="form-group mrg-bt10-right rate" style="margin-top:10px;">
											<label class="control-label col-md-3">比例：</label>
											<div class="col-md-8 inline " >
												
											</div>
										</div>
										<div class="form-group mrg-bt10-right purchaselist" style="display:none" >
											<label class="control-label col-md-3">进货单号：</label>
											<div class="col-md-8 inline purchaseCode">
												
											</div>
										</div>
										<div class="form-group mrg-bt10-right">
											<label class="control-label col-md-3"><span class="required">*</span>申请金额:</label>
											<div class="col-md-8 inline requestPrice" style="text-align: left">
												
											</div>
										</div>
										<div class="form-group mrg-bt10-right">
											<label class="control-label col-md-3">申请说明：</label>
											<div class="col-md-8 inline">
												<textarea name="requestRemark" class="form-control" style="width:480px;resize:none;" readonly=true ></textarea>
												
											</div>
										</div>
									</div>
								</div>
							</div>
							<div class="row col-md-12">
									<div class="col-md-3" style="width: 25%;height:200px">
										<div class="" style="text-align: center;margin-top:30%;font-size:24px;">结算</div>
									</div>
									<div class="col-md-9">
									<div class="box border primary" style="height:150px;margin-top:20px">
										<div class="form-group mrg-bt10-right" style="margin-top:20px">
											<label class="control-label col-md-3"><span class="required">*</span>结算金额:</label>
											<div class="col-md-8 inline" style="text-align: left">
												<input type="text" class="form-control" style="width:130px" name="settlementPrice" onkeypress="return $.IsDecimal(event);" onblur="return $.IsMoney(this);"  onfocus="this.select()" onmouseover="this.onfocus()" placeholder="请输入申请金额" maxlength="10" />
											</div>
										</div>
										<div class="form-group mrg-bt10-right">
											<label class="control-label col-md-3">结算说明：</label>
											<div class="col-md-8 inline">
												<textarea name="remark" class="form-control" style="width:480px;resize:none;" ></textarea>
												
											</div>
										</div>
									</div>
								</div>
								<div class="row" style="height: 30px;">
								<div class="col-md-12 update" style="text-align: center;">
									<div class="box ">
										<a href="javascript:;"  class="btn btn-success config bt-submit" style="width: 100px">
											保存
										</a>
										<a href="javascript:;"  class="btn btn-danger bt-abort" style="width: 100px">
											驳回
										</a>
									</div>
								</div>
					    </div>
							</form>
							<!-- /SAMPLE -->

							<div class="footer-tools">
								<span class="go-top">
								<i class="fa fa-chevron-up"></i> Top
							</span>
							</div>
						</div>
						<!-- /CONTENT-->
					</div>
				</div>
			</div>
		</section>
		<!--/PAGE -->
		<!-- JAVASCRIPTS -->
		<!-- Placed at the end of the document so the pages load faster -->

		<!-- BOOTSTRAP -->
		<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>

		<!-- BLOCK UI -->
		<script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>
		<!--bootbox-->
		<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
		<!-- AUTOSIZE -->
		<script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>
		<!-- spinner -->
		<script src="../../js/spinner/spin.js"></script>
		<!-- INPUT MASK -->
		<script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>

		<!-- SELECT2 -->
		<script type="text/javascript" src="../../js/select2/select2.min.js"></script>

        <script type="text/javascript" src="../../js/datepicker/datepicker.js"></script>
        <script src="../../js/jquery-validate/jquery.validate.min.js"></script>
		<!-- COOKIE -->
		<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
		<!-- CUSTOM SCRIPT -->
		<script src="../../js/script.js"></script>

		<script src="../../js/Sortable.min.js"></script>
		<script>
			var AddSettlement = function() {
			var id=null,type=null;
			var settlementMode = "";

			var updateSettlement=function(){
				var settlement={};
				settlement.id=$("[name=id]").val();
	            settlement.settlementRemark=$("[name=remark]").val();
	            settlement.settlementPrice=$("input[name=settlementPrice]").val();
	            settlement.settlementStatus=$(this).hasClass("bt-abort")?"Abort":"Settlemented";
				settlement.settlementMode = settlementMode;
	            if($(this).hasClass("bt-abort")&&settlement.settlementRemark==""){
	            	$.alert("请输入结算说明");
	            	return false;
	            }
	            if(settlement.settlementPrice==""&&$(this).hasClass("bt-submit")){
	            	$.alert("请输入结算金额");
	            	return false;
	            }
	            $.confirm("确认提交结算?",function(){
	               $.blockUI();
	               $.ajax({
						type: "post",
						url: App.getContextPath() + "admin/settlement/saveSettlement.do",
						data:$.param({settlement:JSON.stringify(settlement)}),
						async: true,
						success: function(result) {
						 $.unblockUI();
							location.href="settlement_list.html";
						}
					});
	            });
			};
			
			var getSettlement=function(){
				$.ajax({
					type: "post",
					url: App.getContextPath()+"admin/settlement/getSettlementById.do",
					async: true,	
					data:{id:id},
					success: function(result) {
						$(".supplierName").html(result.supplier.supplierName);
						$(".contractCode").html(result.contractCode);
						$(".contractPrice").html(format_thousands(result.contract.contractPrice));
						
						 var rate=result.contract.prePercent*100+"%";
						 settlementMode = result.settlementMode;
						if(result.settlementMode=="PreMoney")
						$(".settlementMode").html("预付款");
						if(result.settlementMode=="SecondMoney"){
							var url="<a href='/pages/instock/detail.html?pid="+result.purchaseCode+"' target=_self>"+result.purchaseCode+"</a>"
							$(".purchaseCode").append(url);
							$(".settlementMode").html("提货款");
							$(".purchaselist").show();
							rate=result.contract.pickPercent*100+"%";
							
						}else{
							$(".rate").show();
							$(".purchaselist").hide();
						}						
						if(result.settlementMode=="LastMoney"){
							$(".settlementMode").html("尾款");
							rate=result.contract.endPercent*100+"%";
						}
							
						if(result.settlementMode=="DepositMoney")
						{$(".settlementMode").html("保证金");$(".rate").hide();}
						$(".rate>div").html(rate);
						$(".requestPrice").html(format_thousands(result.requestPrice));
						$("[name=requestRemark]").val(result.requestRemark);
						
						if(type==1)//查看
						{
							$(".update").hide();
							$("[name=settlementPrice]").val(format_thousands(result.settlementPrice)).attr("readonly",true);
							$("[name=remark]").val(result.settlementRemark).attr("readonly",true);
						}
					}
				});
			}
			

				return {
					init: function() {
						 id=$.getUrlParam("id");
						 type=$.getUrlParam("type");
						 $("[name=id]").val(id);
						 getSettlement();						
						App.init();
						$(".bt-submit,.bt-abort").click(updateSettlement);
					}
				}
			}();
			$(function() {
				$("#header").load("../head.html");
				AddSettlement.init();
			});
		</script>

		<!-- /JAVASCRIPTS -->
	</body>

</html>